<?php

/**
 * recovery short summary.
 *
 * recovery description.
 *
 * @version 1.0
 * @author GALAXY
 */
class Recovery extends Goods_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->Model('Goods_model');
        $this->load->library('form_validation');
    }
    public function goodslist()
    {
        $cupge=$this->input->get('page');
        $cupge=empty($cupge) || $cupge=="0"?1:$cupge;

        $pagesize=10;
        $one=$this->Goods_model->get_page($cupge,$pagesize,"a.*,IFNULL(sum(goods_inventory.inventory_count),0)  as inventory_count","goods","order by goods_id desc","goods_id","where is_del=1","LEFT JOIN goods_inventory on goods_inventory.goods_id=a.goods_id GROUP BY a.goods_id ORDER BY a.goods_id desc");
        $this->load->library('page');
        $p=new Page();
        $data['goodsList']=arrayToObject($one['objlist']);
        $p->init($one['count'][0]->_count,5,$cupge,$pagesize,site_url('admin/goods/goodslist'));
        $data['links']=$p->showPages(1);
        $this->load->view('admin/recovery/goodslist.html',$data);

    }

    public function viewgoods()
    {
        $goodsid=$this->uri->segment(4);
        $this->load->Model('Good_material_model');
        $this->load->Model('Goods_style_model');
        $data['return']=$this->input->get('return');
        $data['materialList']=$this->Good_material_model->get_allgood_material();
        $data['stylelList']=$this->Goods_style_model->get_allgoods_style();
        $data['goodsModel']=$this->Goods_model->get_goods_by_id($goodsid);
        $this->load->view('admin/recovery/viewgoods.html',$data);
    }

    public function enable_goods()
    {
        $goodsid=$this->uri->segment(4);
        $this->load->library('ajaxMsgModel');
        $goodsModel=new Goods_model();
        $res= $goodsModel->enable_goods($goodsid);
        if($res)
        {
            $this->ajaxmsgmodel->Msg='修改成功';
            $this->ajaxmsgmodel->Statu='ok';
            $this->ajaxmsgmodel->BackUrl=$this->input->get('returnurl');
        }
        else
        {
            $this->ajaxmsgmodel->Msg='修改失败';
            $this->ajaxmsgmodel->Statu='err';
        }
        echo(json_encode($this->ajaxmsgmodel));
    }

    public function batchenable_goods()
    {
        $goods_ids=$this->input->post('items');
        $this->load->library('ajaxMsgModel');
        $backurl=$this->input->get('returnurl');
        $goodsModel=new Goods_model();
        $goods_idsArray=explode('|',trim($goods_ids,'|'));
        $res=0;
        if(count($goods_idsArray)>0)
        {
            $res=$goodsModel->batchenable_goods($goods_idsArray);
        }
        else
        {
            $this->ajaxmsgmodel->Msg='未选择商品';
            $this->ajaxmsgmodel->Statu='err';
        }
        if($res>0)
        {
            $this->ajaxmsgmodel->Msg='操作成功';
            $this->ajaxmsgmodel->Statu='ok';
            $this->ajaxmsgmodel->BackUrl=$backurl;
        }
        else
        {
            $this->ajaxmsgmodel->Msg='操作失败';
            $this->ajaxmsgmodel->Statu='err';
        }
        echo(json_encode($this->ajaxmsgmodel));
    }
}